#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL n,k;
LL a[maxn],sum[maxn],mi[maxn],b[maxn];
bool check(LL mid){
    for(LL i=1;i<n+10;i++) sum[i]=b[i]=0,mi[i]=0x3f3f3f3f;
    for(LL i=1;i<=n;i++){
        if(a[i]>=mid) b[i]=1;
        else b[i]=-1;
    }
    for(LL i=1;i<=n;i++) sum[i]=sum[i-1]+b[i];
    for(LL i=1;i<=n;i++) mi[i]=min(mi[i-1],sum[i]);
    for(LL i=k;i<=n;i++){
        LL temp=sum[i]-mi[i-k];
        if(temp>0) return true;
    }
    return false;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  cin>>n>>k;
  for(LL i=1;i<=n;i++) cin>>a[i];
  LL l=1;LL r=1e18;
  while(l<r){
    LL mid=(l+r+1)>>1;
    if(check(mid)) l=mid;
    else r=mid-1;
  }
  cout<<l<<"\n";
return 0;
}
